package cn.tedu.aop.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Order(5)
@Aspect
@Component
public class TimeAspect {

    @Pointcut("@annotation(cn.tedu.aop.base.annotation.RequiredTime)")
    public void doTime(){}
    @Before("doTime()")
    public void doBefore(JoinPoint joinPoint){
        System.out.println("@Before");
    }
    @After("doTime()")
    public void doAfter(JoinPoint joinPoint){
        System.out.println("@After");
    }
    @AfterReturning("doTime()")
    public void doAfterReturning(JoinPoint joinPoint){
        System.out.println("@AfterReturning");
    }
    @AfterThrowing("doTime()")
    public void doAfterThrowing(JoinPoint joinPoint){
        System.out.println("@AfterThrowing");
    }
    @Around("doTime()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable{
        System.out.println("Time.@Around.Before");
        try {
            Object proceed = joinPoint.proceed();
            System.out.println("@Around.AfterReturning");
            return proceed;
        }catch (Throwable e){
            System.out.println("@Around.AfterThrowing");
            throw e;
        }finally{
            System.out.println("@Around.After");
        }
    }
}
